package com.mall.server.controller.oms;

import com.mall.model.domain.OmsOrder;
import com.mall.model.dto.OmsMoneyInfoDto;
import com.mall.model.dto.OmsOrderDeliveryDto;
import com.mall.model.dto.OmsOrderDto;
import com.mall.model.dto.OmsReceiverInfoDto;
import com.mall.model.vo.CommonPage;
import com.mall.model.vo.CommonResult;
import com.mall.model.vo.OmsOrderDetailVo;
import com.mall.server.service.oms.OmsOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author : xyiaao
 * @createDate : 2022/4/2 10:05
 */
@CrossOrigin
@RestController
@RequestMapping("/order")
public class OmsOrderController {

    @Autowired
    private OmsOrderService omsOrderService;


    /**
     * 查询订单
     *
     * @param omsOrderDto
     * @return
     */
    @GetMapping("/list")
    public CommonResult list(OmsOrderDto omsOrderDto) {

        CommonPage<OmsOrder> page = omsOrderService.page(omsOrderDto);
        return CommonResult.success(page);
    }


    /**
     * 查询订单详情：订单信息、商品信息、操作记录
     *
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public CommonResult getOmsOrderById(@PathVariable("id") Long id) {

        OmsOrderDetailVo omsOrderDetailVo = omsOrderService.getOmsOrderDetailDtoByOrderId(id);
        return CommonResult.success(omsOrderDetailVo);
    }


    /**
     * 批量删除订单
     *
     * @param ids
     * @return
     */
    @PostMapping("/delete")
    public CommonResult delete(@RequestParam List<Long> ids) {

        omsOrderService.delete(ids);
        return CommonResult.success();
    }


    /**
     * 批量关闭订单
     *
     * @param ids
     * @param note
     * @return
     */
    @PostMapping("/update/close")
    public CommonResult updateClose(@RequestParam List<Long> ids, String note) {

        omsOrderService.updateClose(ids, note);
        return CommonResult.success();
    }


    /**
     * 批量发货
     *
     * @param deliveryParamList
     * @return
     */
    @PostMapping("/update/delivery")
    public CommonResult updateDelivery(@RequestBody List<OmsOrderDeliveryDto> deliveryParamList) {

        omsOrderService.updateDelivery(deliveryParamList);
        return CommonResult.success();
    }

    /**
     * 修改订单费用信息
     *
     * @param moneyInfoParam
     * @return
     */
    @PostMapping("/update/moneyInfo")
    public CommonResult updateMoneyInfo(@RequestBody OmsMoneyInfoDto moneyInfoParam) {

        omsOrderService.updateMoneyInfo(moneyInfoParam);
        return CommonResult.success();
    }


    /**
     * 备注订单
     *
     * @param id
     * @param note
     * @param status
     * @return
     */
    @PostMapping("/update/note")
    public CommonResult updateNote(Long id, String note, Integer status) {

        omsOrderService.updateNote(id, note, status);
        return CommonResult.success();
    }


    /**
     * 修改收获人信息
     *
     * @param receiverInfoParam
     * @return
     */
    @PostMapping("/update/receiverInfo")
    public CommonResult updateReceiverInfo(@RequestBody OmsReceiverInfoDto receiverInfoParam) {

        omsOrderService.updateReceiverInfo(receiverInfoParam);
        return CommonResult.success();
    }

}
